import 'package:flutter/material.dart';
import 'game_screen.dart';

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text(
              '贪吃蛇游戏',
              style: TextStyle(fontSize: 36, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 40),
            ElevatedButton(
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => const GameScreen(initialSpeed: 200),
                  ),
                );
              },
              child: const Text('开始游戏'),
            ),
            const SizedBox(height: 20),
            const Text('选择难度:'),
            const SizedBox(height: 10),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                DifficultyButton(
                  label: '简单',
                  speed: 200,
                  color: Colors.green,
                ),
                const SizedBox(width: 10),
                DifficultyButton(
                  label: '中等',
                  speed: 150,
                  color: Colors.orange,
                ),
                const SizedBox(width: 10),
                DifficultyButton(
                  label: '困难',
                  speed: 100,
                  color: Colors.red,
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

class DifficultyButton extends StatelessWidget {
  final String label;
  final int speed;
  final Color color;
  
  const DifficultyButton({
    super.key,
    required this.label,
    required this.speed,
    required this.color,
  });
  
  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      style: ElevatedButton.styleFrom(backgroundColor: color),
      onPressed: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => GameScreen(initialSpeed: speed),
          ),
        );
      },
      child: Text(label),
    );
  }
}